import * as step from '@flow-step/step-toolkit'
import process from 'process'
import {checkBranchBehind} from './checkBranchBehind'


async function runStep(): Promise<void> {

    let envs = process.env.PATH
    if(process.platform == 'win32' && envs != undefined && !envs.includes('Git')){
        step.error('Please install Git or set global envs first!')
        throw new Error('check git failed!')
    }

    step.info('PIPELINE_ID=' + Number(process.env.PIPELINE_ID));
    step.info('PIPELINE_NAME=' + process.env.PIPELINE_NAME as string);
    step.info('BUILD_NUMBER=' + Number(process.env.BUILD_NUMBER));
    step.info('EMPLOYEE_ID=' + process.env.operator);
    step.info('WORK_SPACE=' + process.env.WORK_SPACE as string);
    step.info('PROJECT_DIR=' + process.env.PROJECT_DIR as string);
    step.info('PLUGIN_DIR=' + process.env.PLUGIN_DIR as string);
    step.info('BUILD_JOB_ID=' + Number(process.env.BUILD_JOB_ID));
    step.info('TARGET_BRANCH='+ process.env.TARGET_BRANCH as string)

    await checkBranchBehind();

}

runStep()
    .then(function () {
        step.success('run step GitCheckBranchBehind successfully!')
    })
    .catch(function (err: Error) {
        step.error(err.message)
        process.exit(-1)
    })
